using AiQiuQuan.Sport.Model.Models;
using AiQiuQuan.Sport.Core;
using AiQiuQuan.Sport.WebApi.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

namespace AiQiuQuan.Sport.WebApi.Controllers
{
    /// <summary>
    /// 会员管理
    /// </summary>
    public class BaseUserController : ApiController
    {
        private readonly IBaseUserService _baseUserService;

        /// <summary>
        /// cotr
        /// </summary>
        public BaseUserController(
            IBaseUserService baseUserService)
        {
            _baseUserService = baseUserService;
        }

        /// <summary>
        /// 登录
        /// </summary>
        [AllowAnonymous]
        [HttpPost("login")]
        public async Task<UnaryResult<UserTokenResultDto>> LoginAsync()
        {
            var result = await _baseUserService.LoginAsync();
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="id">业务编号</param>
        [HttpGet("get")]
        public async Task<UnaryResult<BaseUserDto>> GetAsync(Guid id)
        {
            var result = await _baseUserService.GetAsync(id);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 更新
        /// </summary>
        [HttpPost("update")]
        public async Task<UnaryResult> UpdateAsync(BaseUserUpdateDto request)
        {
            var result = await _baseUserService.UpdateAsync(request);
            return result;
        }

        /// <summary>
        /// 查询用户信息，含用户角色
        /// </summary>
        [HttpPost("query")]
        public async Task<UnaryResult<BaseUserDto>> QueryAsync(BaseUserRoleRequestDto request)
        {
            var result = await _baseUserService.QueryAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        [HttpPost("pagelist")]
        [AllowAnonymous]
        public async Task<UnaryResult<PageResult<BaseUserDto>>> PageListAsync(BaseUserPageRequestDto model)
        {
            var result = await _baseUserService.PageListAsync(model);
            return UnaryResult.From(0, result);
        }

        /// <summary>
        /// 用户实名认证
        /// </summary>
        [HttpPost("authenticate")]
        public async Task<UnaryResult> AuthenticateIDAsync(BaseUserAuthorizeRequestDto request)
        {
            var result = await _baseUserService.AuthenticateIDAsync(request);
            return result;
        }

        /// <summary>
        /// 用户微信openid认证
        /// </summary>
        [HttpPost("authenticate_wxopenid")]
        public async Task<UnaryResult<string>> AuthenticateWxOpenIdAsync()
        {
            var result = await _baseUserService.AuthenticateWxOpenIdAsync();
            return result;
        }
    }
}
